package org.rambadger.command.view;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.yammer.dropwizard.auth.Auth;
import com.yammer.dropwizard.views.View;
import org.rambadger.command.auth.AuthUser;
import org.rambadger.command.representation.User;

public class UserView extends View {
    String title;
    boolean area_users = true;
    boolean hasAdmin = false;
    boolean editable = false;

    @JsonProperty String username;
    @JsonProperty String emailAddress;
    @JsonProperty String firstName;
    @JsonProperty String lastName;
    @JsonProperty int submissionPoints;
    @JsonProperty int reviewPoints;

    public UserView(AuthUser authUser, User user) {
        super("/profile.mustache");
        this.username = user.getUsername();
        this.emailAddress = user.getEmailAddress();
        this.firstName = user.getFirstName();
        this.lastName = user.getLastName();
        this.submissionPoints = user.getSubmissionPoints();
        this.reviewPoints = user.getReviewPoints();
        if (authUser !=null)
        this.hasAdmin = authUser.hasAdmin();

        if (authUser !=null && (authUser.hasAdmin() || authUser.getUsername() == this.username))
            editable = true;

        this.title = ": " + user.getUsername() + "'s Profile";
    }
}
